package com.zhangjun.work5.service.Impl;

import com.zhangjun.work5.entity.Student;
import com.zhangjun.work5.entity.TransferForm;
import com.zhangjun.work5.mapper.StudentMapper;
import com.zhangjun.work5.service.TransferService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 张钧
 * @Description
 * @create 2022-11-11 11:24
 */
@Service
public class TransferServiceImpl implements TransferService {

	@Resource
	StudentMapper studentMapper;

	@Override
	public List<Student> getStudents() {
		return studentMapper.getStudents();
	}

	@Override
	@Transactional
	public void transferBalance(TransferForm transferForm) {
		studentMapper.updateBalance(transferForm.getSendId(),transferForm.getMoney());
//		int i = 10 / 0;
		studentMapper.updateBalance(transferForm.getReceiveId(),transferForm.getMoney().negate());
	}
}
